package com.ruoyi.kk.division.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kk.division.domain.KkSysAdministrativeDivision;
import com.ruoyi.kk.division.service.IKkSysAdministrativeDivisionService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 全国行政区划信息Controller
 * 
 * @author kk
 * @date 2025-06-09
 */
@RestController
@RequestMapping("/kk/division")
public class KkSysAdministrativeDivisionController extends BaseController
{
    @Autowired
    private IKkSysAdministrativeDivisionService kkSysAdministrativeDivisionService;

    /**
     * 查询全国行政区划信息列表
     */
    @PreAuthorize("@ss.hasPermi('kk:division:list')")
    @GetMapping("/list")
    public AjaxResult list(KkSysAdministrativeDivision kkSysAdministrativeDivision)
    {
        List<KkSysAdministrativeDivision> list = kkSysAdministrativeDivisionService.selectKkSysAdministrativeDivisionList(kkSysAdministrativeDivision);
        return success(list);
    }

    /**
     * 导出全国行政区划信息列表
     */
    @PreAuthorize("@ss.hasPermi('kk:division:export')")
    @Log(title = "全国行政区划信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KkSysAdministrativeDivision kkSysAdministrativeDivision)
    {
        List<KkSysAdministrativeDivision> list = kkSysAdministrativeDivisionService.selectKkSysAdministrativeDivisionList(kkSysAdministrativeDivision);
        ExcelUtil<KkSysAdministrativeDivision> util = new ExcelUtil<KkSysAdministrativeDivision>(KkSysAdministrativeDivision.class);
        util.exportExcel(response, list, "全国行政区划信息数据");
    }

    /**
     * 获取全国行政区划信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('kk:division:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(kkSysAdministrativeDivisionService.selectKkSysAdministrativeDivisionByCode(code));
    }

    /**
     * 新增全国行政区划信息
     */
    @PreAuthorize("@ss.hasPermi('kk:division:add')")
    @Log(title = "全国行政区划信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KkSysAdministrativeDivision kkSysAdministrativeDivision)
    {
        return toAjax(kkSysAdministrativeDivisionService.insertKkSysAdministrativeDivision(kkSysAdministrativeDivision));
    }

    /**
     * 修改全国行政区划信息
     */
    @PreAuthorize("@ss.hasPermi('kk:division:edit')")
    @Log(title = "全国行政区划信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KkSysAdministrativeDivision kkSysAdministrativeDivision)
    {
        return toAjax(kkSysAdministrativeDivisionService.updateKkSysAdministrativeDivision(kkSysAdministrativeDivision));
    }

    /**
     * 删除全国行政区划信息
     */
    @PreAuthorize("@ss.hasPermi('kk:division:remove')")
    @Log(title = "全国行政区划信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes)
    {
        return toAjax(kkSysAdministrativeDivisionService.deleteKkSysAdministrativeDivisionByCodes(codes));
    }
}
